package rsj.service.customer;

import com.alibaba.fastjson.JSON;
import com.rlyy.aibase.utils.base.MapNode;
import rsj.api.customer.entity.Customer;
import rsj.api.customer.entity.CustomerQueryParam;
import rsj.context.ApplicationContextUtil;
import rsj.sql.customer.CustomerDao;

import java.util.List;

/**
 * 客户
 *
 * @author yuanqinglong
 * @since 2021/7/14 11:22
 */
public interface ICustomerService {

    /**
     * 客户ID
     */
    String customerIdPrefix = "CONCAT('RSJ',LPAD(cust_id::text,4,'0')";

    /**
     * 客户列表
     *
     * @param customerQueryParam 客户查询参数
     * @return {@link List<Customer>}
     */
    List<Customer> customerList(CustomerQueryParam customerQueryParam);


    /**
     * 客户数
     *
     * @param customerQueryParam 客户查询参数
     * @return int
     */
    int customerCount(CustomerQueryParam customerQueryParam);


    /**
     * 添加客户
     *
     * @param customer 客户
     */
    void addCustomer(Customer customer);


    /**
     * 更新客户
     *
     * @param customer 客户
     */
    void updateCustomer(Customer customer);


    /**
     * 得到客户
     *
     * @param customerId 客户id
     * @return {@link Customer}
     */
    Customer getCustomer(String customerId);


    /**
     * 选择客户列表
     *
     * @param customerQueryParam 客户查询参数
     * @return {@link List<Customer>}
     */
    List<Customer> selectCustomerList(CustomerQueryParam customerQueryParam);

    /**
     * 通过id获取客户
     *
     * @param customerId 客户id
     * @return {@link Customer}
     */
    default Customer getCustomerById(Integer customerId){
        CustomerDao customerDao = ApplicationContextUtil.getBean(CustomerDao.class);
        MapNode customerById = customerDao.getCustomerById(customerId);
        return JSON.parseObject(JSON.toJSONString(customerById.toMap()), Customer.class);
    }
}
